---
title: "Regression_Models_1"
author: "Omar Hammoud Gallego, Roberto Foa, Xavier Romero-Vidal"
date: "12/02/2022"
output:
  html_document:
    code_folding: hide
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
	echo = TRUE,
	message = FALSE,
	warning = FALSE
)
```

## Upload Data and Packages

```{r, upload packages}

library(tm)
library(tidytext)
library(dplyr)
library(SnowballC)
library(ggplot2)
library(sjlabelled)

#install.packages("textdata")
library(textdata)

#install.packages("reshape")
library(reshape)
library(tidyverse)

library(stargazer)

library(sjPlot)
library(sjmisc)
library(sjlabelled)

library(lubridate)

#install.packages("dotwhisker")
library("dotwhisker")
library(lme4)

# To clean environment
#rm(list = ls())
```


```{r, upload data}

#Xavi Path
Mod_Dataset<- read.csv("/Volumes/GoogleDrive/Other computers/My Laptop/Documents/_University/2021 Cambridge/_Project/_Tracker/Data/combined_survey_tweets_february_11.csv", stringsAsFactors = TRUE)

# Omar Upload. Comment Out to run your own, 
#setwd("/Users/HammoudG/OneDrive - London School of Economics/Satisfaction_Democracy_Project/")

setwd("C:/Users/omarh//OneDrive - London School of Economics/Satisfaction_Democracy_Project/")


Mod_Dataset<- read.csv("combined_survey_tweets_february_11.csv", stringsAsFactors = TRUE)

#summary(Mod_Dataset)
```

```{r, check factors reference levels}

Mod_Dataset$lastvote = relevel(Mod_Dataset$lastvote, ref = "Did not vote")

Mod_Dataset$profile_gross_household<- as.character(Mod_Dataset$profile_gross_household)


#Transform income into integer
Mod_Dataset2 <- Mod_Dataset %>% 
 mutate(profile_gross_household = recode (profile_gross_household, 
    "under £5,000 per year"= "1", 
    "£5,000 to £9,999 per year"= "2",
    "£10,000 to £14,999 per year"= "3",
    "£15,000 to £19,999 per year"= "4",
    "£20,000 to £24,999 per year"= "5",
    "£25,000 to £29,999 per year"= "6",
    "£30,000 to £34,999 per year"= "7",
    "£35,000 to £39,999 per year"= "8",
    "£40,000 to £44,999 per year"= "9",
    "£45,000 to £49,999 per year"= "10",
    "£50,000 to £59,999 per year"= "11",
    "£60,000 to £69,999 per year"= "12",
    "£70,000 to £99,999 per year"= "13",
    "£100,000 to £149,999 per year"= "14",
    "£150,000 and over"= "15", 
    "Don't know"= "NA",
    "Prefer_not_to_answer" = "NA"))

Mod_Dataset2$profile_gross_household<- as.numeric(Mod_Dataset2$profile_gross_household)

#Standardizing numerical (salience and sentiment)
#install.packages("standardize")
library(standardize)
Mod_Dataset2$profile_gross_household<- scale(Mod_Dataset2$profile_gross_household)
Mod_Dataset2$weekavg_Climate_Change <- scale(Mod_Dataset2$weekavg_Climate_Change)
Mod_Dataset2$weekavg_Covid <- scale(Mod_Dataset2$weekavg_Covid)
Mod_Dataset2$weekavg_Crime <- scale(Mod_Dataset2$weekavg_Crime)
Mod_Dataset2$weekavg_Daily_News <- scale(Mod_Dataset2$weekavg_Daily_News)
Mod_Dataset2$weekavg_Enterteinment <- scale(Mod_Dataset2$weekavg_Enterteinment)
Mod_Dataset2$weekavg_Football <- scale(Mod_Dataset2$weekavg_Football)
Mod_Dataset2$weekavg_Hong_Kong <- scale(Mod_Dataset2$weekavg_Hong_Kong)
Mod_Dataset2$weekavg_Lockdown <- scale(Mod_Dataset2$weekavg_Lockdown)
Mod_Dataset2$weekavg_Lockdown_Travel <- scale(Mod_Dataset2$weekavg_Lockdown_Travel)
Mod_Dataset2$weekavg_Police_Brutality <- scale(Mod_Dataset2$weekavg_Police_Brutality)
Mod_Dataset2$weekavg_Puppy_News <- scale(Mod_Dataset2$weekavg_Puppy_News)
Mod_Dataset2$weekavg_Royal_Family <- scale(Mod_Dataset2$weekavg_Royal_Family)
Mod_Dataset2$weekavg_Uk_Politics <- scale(Mod_Dataset2$weekavg_Uk_Politics)
Mod_Dataset2$weekavg_US_Politics <- scale(Mod_Dataset2$weekavg_US_Politics)
Mod_Dataset2$weekavg_Weather <- scale(Mod_Dataset2$weekavg_Weather)

Mod_Dataset2$weekly_mean_sentiment_R_Climate_Change <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Climate_Change)
Mod_Dataset2$weekly_mean_sentiment_R_Covid <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Covid)
Mod_Dataset2$weekly_mean_sentiment_R_Crime <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Crime)
Mod_Dataset2$weekly_mean_sentiment_R_Daily_News <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Daily_News)
Mod_Dataset2$weekly_mean_sentiment_R_Enterteinment <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Enterteinment)
Mod_Dataset2$weekly_mean_sentiment_R_Football <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Football)
Mod_Dataset2$weekly_mean_sentiment_R_Hong_Kong <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Hong_Kong)
Mod_Dataset2$weekly_mean_sentiment_R_Lockdown <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Lockdown)
Mod_Dataset2$weekly_mean_sentiment_R_Lockdown_Travel <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Lockdown_Travel)
Mod_Dataset2$weekly_mean_sentiment_R_Police_Brutality <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Police_Brutality)
Mod_Dataset2$weekly_mean_sentiment_R_Puppy_News <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Puppy_News)
Mod_Dataset2$weekly_mean_sentiment_R_Royal_Family <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Royal_Family)
Mod_Dataset2$weekly_mean_sentiment_R_Uk_Politics <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Uk_Politics)
Mod_Dataset2$weekly_mean_sentiment_R_US_Politics <- scale(Mod_Dataset2$weekly_mean_sentiment_R_US_Politics)
Mod_Dataset2$weekly_mean_sentiment_R_Weather <- scale(Mod_Dataset2$weekly_mean_sentiment_R_Weather)

#Week as factor
Mod_Dataset2$week <- as.factor(Mod_Dataset2$week)
#Week as ticker
Mod_Dataset2$week <- as.numeric(Mod_Dataset2$week)

```

```{r, date into date format}
# factor into character
Mod_Dataset$created_at<- as.character(Mod_Dataset$created_at)

# to transform character into date
Mod_Dataset$created_at <- strptime(Mod_Dataset$created_at, format = "%Y-%m-%d", tz = "GMT")

# Posixct into date
Mod_Dataset$created_at <- as.Date(as.character(as.POSIXct(Mod_Dataset$created_at)))


```

# Merge economic data

```{r, merge econ data, eval = FALSE}

# upload monthly economic data
# for mac
setwd("/Users/HammoudG/Documents/GitHub/Satisfaction_Democracy/data-raw/Economic_data/")

ECON<- read.csv("UK_monthly_economic_data.csv")


# factor into character
ECON$date<- as.character(ECON$date)

# to transform character into date
ECON$date <- strptime(ECON$date, format = "%Y-%m-%d", tz = "GMT")

# Posixct into date
ECON$date <- as.Date(as.character(as.POSIXct(ECON$date)))


# MERGE with Mod_Dataset
Mod_Dataset1<- Mod_Dataset %>%
    group_by(month = lubridate::floor_date(created_at, "month")) %>%
    left_join(ECON, by = c("month"="date")) %>%
    ungroup()

# Upload Covid daily Data

# Omar Upload. Comment Out to run your own, 
setwd("/Users/HammoudG/OneDrive - London School of Economics/Satisfaction_Democracy_Project/")

COVID<- read.csv("owid-covid-data.csv")

COVID$location<- as.factor(as.character(COVID$location))


COVID<- COVID %>%
    select(location, date, new_deaths:new_people_vaccinated_smoothed_per_hundred) %>%
    filter(location == "United Kingdom")

# factor into character
COVID$date<- as.character(COVID$date)

# to transform character into date
COVID$date <- strptime(COVID$date, format = "%Y-%m-%d", tz = "GMT")

# Posixct into date
COVID$date <- as.Date(as.character(as.POSIXct(COVID$date)))


# MERGE COVID DATA WITH REGRESSION DATASET

Mod_Dataset2<- Mod_Dataset1 %>%
    left_join(COVID, by = c("created_at"="date")) 



# To save new dataset with covid and economic data for regression modelling 
setwd("/Users/HammoudG/OneDrive - London School of Economics/Satisfaction_Democracy_Project/")

write.csv(Mod_Dataset2, "combined_survey_tweets_february_11.csv")

```



## Regressions

```{r, run model 1, results = 'asis'}
# Good variables
# weekavg
# weekly_mean_sentiment_R
#glimpse(Mod_Dataset)
#glimpse(Mod_Dataset$week)

## CHANGE NAMES THREE TOPICS

first_model<- lm(DEM_SAT ~ weekavg_Climate_Change+
                          weekavg_Covid +
                          weekavg_Crime+
                          weekavg_Daily_News+
                          weekavg_Enterteinment+
                          weekavg_Football+
                          weekavg_Hong_Kong+
                          weekavg_Lockdown+
                          weekavg_Lockdown_Travel+
                          weekavg_Police_Brutality+
                          weekavg_Puppy_News+
                          weekavg_Royal_Family+
                          weekavg_Uk_Politics+
                          weekavg_US_Politics+
                          weekavg_Weather + 
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week, 
   data= Mod_Dataset)
          
#summary(first_model)


```

```{r, run model 2 with weekly sentiment, results = 'asis'}

## CHANGE MEAN WEEKLY SENTIMENT!!! AND ALSO IN MODEL 3 THE INTERACTION


second_model<- lm(DEM_SAT ~ weekavg_Climate_Change+
                          weekavg_Covid +
                          weekavg_Crime+
                          weekavg_Daily_News+
                          weekavg_Enterteinment+
                          weekavg_Football+
                          weekavg_Hong_Kong+
                          weekavg_Lockdown+
                          weekavg_Lockdown_Travel+
                          weekavg_Police_Brutality+
                          weekavg_Puppy_News+
                          weekavg_Royal_Family+
                          weekavg_Uk_Politics+
                          weekavg_US_Politics+
                          weekavg_Weather +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
              weekavg_Climate_Change+
                          weekly_mean_sentiment_R_Covid +
                          weekly_mean_sentiment_R_Crime+
                          weekly_mean_sentiment_R_Daily_News+
                          weekly_mean_sentiment_R_Enterteinment+
                          weekly_mean_sentiment_R_Football+
                          weekly_mean_sentiment_R_Hong_Kong+
                          weekly_mean_sentiment_R_Lockdown+
                          weekly_mean_sentiment_R_Lockdown_Travel+
                          weekly_mean_sentiment_R_Police_Brutality+
                          weekly_mean_sentiment_R_Puppy_News+
                          weekly_mean_sentiment_R_Royal_Family+
                          weekly_mean_sentiment_R_Uk_Politics+
                          weekly_mean_sentiment_R_US_Politics+
                          weekly_mean_sentiment_R_Weather , 
   data= Mod_Dataset)
          
#glimpse(Mod_Dataset)

#summary(first_model)
#summary(second_model)

#stargazer(first_model, second_model, type = 'html')


```

```{r, run model 3 with interaction topic and sentiment, results = 'asis'}



third_model<- lm(DEM_SAT ~ weekavg_Brexit+
                   weekavg_Climate_Change+
                   weekavg_Covid_and_Health+
                   weekavg_Crime+
                   weekavg_Daily_News+
                   weekavg_Enterteinment+
                   weekavg_Football+
                   weekavg_Pandemic+
                   weekavg_Pandemic_Measures+
                   weekavg_Pandemic_Restrictions+
                   weekavg_Royal_Family+
                   weekavg_US_Politics +
                   weekavg_Weather+
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
             
             weekly_mean_sentiment_R_Brexit+
             weekly_mean_sentiment_R_Climate_Change+
                   weekly_mean_sentiment_R_Covid_and_Health+
                   weekly_mean_sentiment_R_Crime+
                   weekly_mean_sentiment_R_Daily_News+
                   weekly_mean_sentiment_R_Enterteinment+
                   weekly_mean_sentiment_R_Football+
                   weekly_mean_sentiment_R_Pandemic+
                   weekly_mean_sentiment_R_Pandemic_Measures+
                   weekly_mean_sentiment_R_Pandemic_Restrictions+
                   weekly_mean_sentiment_R_Royal_Family+
                   weekly_mean_sentiment_R_US_Politics+
                 + weekly_mean_sentiment_R_Weather +

                     weekavg_Brexit*weekly_mean_sentiment_R_Brexit+
                   weekavg_Climate_Change*weekly_mean_sentiment_R_Climate_Change+
                   weekavg_Covid_and_Health*weekly_mean_sentiment_R_Covid_and_Health+
                   weekavg_Crime*weekly_mean_sentiment_R_Crime+
                   weekavg_Daily_News*weekly_mean_sentiment_R_Daily_News+
                   weekavg_Enterteinment*weekly_mean_sentiment_R_Enterteinment+
                   weekavg_Football*weekly_mean_sentiment_R_Football+
                   weekavg_Pandemic*weekly_mean_sentiment_R_Pandemic+
                   weekavg_Pandemic_Measures*weekly_mean_sentiment_R_Pandemic_Measures+
                   weekavg_Pandemic_Restrictions*weekly_mean_sentiment_R_Pandemic_Restrictions+
                   weekavg_Royal_Family*weekly_mean_sentiment_R_Royal_Family+
                   weekavg_US_Politics*weekly_mean_sentiment_R_US_Politics+
                   weekavg_Weather*weekly_mean_sentiment_R_Weather

             , 
   data= Mod_Dataset)
          
#summary(third_model)

#tab_model(third_model)
```

```{r, run model 4 with interaction topic and sentiment plus retweets for salience, results = 'asis', eval = FALSE}



fourth_model<- lm(DEM_SAT ~ weekavg_Pandemic_Restrictions+
                 weekavg_Enterteinment+
                   weekavg_Everyday_News+
                   weekavg_Everyday_Tragedies+
                   weekavg_Family_News+
                   weekavg_Football_and_Other_Sports+
                   weekavg_Home_Stuff+
                   weekavg_Society+
                   weekavg_Life_under_Lockdown+
                   weekavg_Royal_family+
                   weekavg_Pandemic+
                   weekavg_UK_Politics+
                   weekavg_US_Politics+
                 + weekavg_Violence_Crime +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
             weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekly_mean_sentiment_R_Enterteinment+
                   weekly_mean_sentiment_R_Everyday_News+
                   weekly_mean_sentiment_R_Everyday_Tragedies+
                   weekly_mean_sentiment_R_Family_News+
                   weekly_mean_sentiment_R_Football_and_Other_Sports+
                   weekly_mean_sentiment_R_Home_Stuff+
                   weekly_mean_sentiment_R_Society+
                   weekly_mean_sentiment_R_Life_under_Lockdown+
                   weekly_mean_sentiment_R_Royal_family+
                   weekly_mean_sentiment_R_Pandemic+
                   weekly_mean_sentiment_R_UK_Politics+
                   weekly_mean_sentiment_R_US_Politics+
                  weekly_mean_sentiment_R_Violence_Crime +
             weekavg_Pandemic_Restrictions*weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekavg_Family_News*weekly_mean_sentiment_R_Family_News+
             weekavg_Royal_family*weekly_mean_sentiment_R_Royal_family+
             weekavg_Pandemic*weekly_mean_sentiment_R_Pandemic+
             weekavg_UK_Politics*weekly_mean_sentiment_R_UK_Politics+
             weekavg_US_Politics*weekly_mean_sentiment_R_US_Politics+
             weekavg_Violence_Crime*weekly_mean_sentiment_R_Violence_Crime+
             tot_retweets_topic_Covid_in_the_UK+
             tot_retweets_topic_Enterteinment+
             tot_retweets_topic_Everyday_News+
             tot_retweets_topic_Everyday_Tragedies+
             tot_retweets_topic_Family_News+
             tot_retweets_topic_Football_and_Other_Sports+
             tot_retweets_topic_Home_Stuff+
             tot_retweets_topic_Life_in_the_UK+
             tot_retweets_topic_Life_under_Lockdown+
             tot_retweets_topic_Royal_family+
             tot_retweets_topic_UK_Government_Pandemic_Response+
             tot_retweets_topic_UK_Politics+
             tot_retweets_topic_US_Politics+
             tot_retweets_topic_Violence_Crime
             
             
             
             
             
             
             , 
   data= Mod_Dataset)
          
#summary(third_model)

#tab_model(fourth_model)

#glimpse(Mod_Dataset)
```

```{r, run model 5 with interaction topic and sentiment and interaction of topics with retweets for salience, results = 'asis', eval = FALSE}

# DO NOT USE CONFOUNDING CLEAR

fifth_model<- lm(DEM_SAT ~ weekavg_Pandemic_Restrictions:tot_retweets_topic_Covid_in_the_UK+
             weekavg_Enterteinment:tot_retweets_topic_Enterteinment+
             weekavg_Everyday_News:tot_retweets_topic_Everyday_News+
             weekavg_Everyday_Tragedies:tot_retweets_topic_Everyday_Tragedies+
             weekavg_Family_News:tot_retweets_topic_Family_News+
             weekavg_Football_and_Other_Sports:tot_retweets_topic_Football_and_Other_Sports+
             weekavg_Home_Stuff:tot_retweets_topic_Home_Stuff+
             weekavg_Society:tot_retweets_topic_Life_in_the_UK+
             weekavg_Life_under_Lockdown:tot_retweets_topic_Life_under_Lockdown+
             weekavg_Royal_family:tot_retweets_topic_Royal_family+
             weekavg_Pandemic:tot_retweets_topic_UK_Government_Pandemic_Response+
             weekavg_UK_Politics:tot_retweets_topic_UK_Politics+
             weekavg_US_Politics:tot_retweets_topic_US_Politics+
             weekavg_Violence_Crime:tot_retweets_topic_Violence_Crime+
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
             weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekly_mean_sentiment_R_Enterteinment+
                   weekly_mean_sentiment_R_Everyday_News+
                   weekly_mean_sentiment_R_Everyday_Tragedies+
                   weekly_mean_sentiment_R_Family_News+
                   weekly_mean_sentiment_R_Football_and_Other_Sports+
                   weekly_mean_sentiment_R_Home_Stuff+
                   weekly_mean_sentiment_R_Society+
                   weekly_mean_sentiment_R_Life_under_Lockdown+
                   weekly_mean_sentiment_R_Royal_family+
                   weekly_mean_sentiment_R_Pandemic+
                   weekly_mean_sentiment_R_UK_Politics+
                   weekly_mean_sentiment_R_US_Politics+
                  weekly_mean_sentiment_R_Violence_Crime +
             weekavg_Pandemic_Restrictions*weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekavg_Family_News*weekly_mean_sentiment_R_Family_News+
             weekavg_Royal_family*weekly_mean_sentiment_R_Royal_family+
             weekavg_Pandemic*weekly_mean_sentiment_R_Pandemic+
             weekavg_UK_Politics*weekly_mean_sentiment_R_UK_Politics+
             weekavg_US_Politics*weekly_mean_sentiment_R_US_Politics+
             weekavg_Violence_Crime*weekly_mean_sentiment_R_Violence_Crime
          
             
             
             
             
             
             
             , 
   data= Mod_Dataset)
          
#summary(third_model)

tab_model(fifth_model)

#glimpse(Mod_Dataset)
```

```{r, run model 6 with interaction sentiment and retweets , results = 'asis', eval = FALSE}

# DO NOT USE CONFOUNDING CLEAR

sixth_model<- lm(DEM_SAT ~ mean_weekly_sentiment_Everyday_News:tot_retweets_topic_Covid_in_the_UK+
             mean_weekly_sentiment_Enterteinment:tot_retweets_topic_Enterteinment+
             mean_weekly_sentiment_Everyday_News:tot_retweets_topic_Everyday_News+
             mean_weekly_sentiment_Everyday_Tragedies:tot_retweets_topic_Everyday_Tragedies+
             mean_weekly_sentiment_Family_News:tot_retweets_topic_Family_News+
             mean_weekly_sentiment_Football_and_Other_Sports:tot_retweets_topic_Football_and_Other_Sports+
             mean_weekly_sentiment_Home_Stuff:tot_retweets_topic_Home_Stuff+
             mean_weekly_sentiment_Life_in_the_UK:tot_retweets_topic_Life_in_the_UK+
             mean_weekly_sentiment_Life_under_Lockdown:tot_retweets_topic_Life_under_Lockdown+
             mean_weekly_sentiment_Royal_family:tot_retweets_topic_Royal_family+
       mean_weekly_sentiment_UK_Government_Pandemic_Response:tot_retweets_topic_UK_Government_Pandemic_Response+
             mean_weekly_sentiment_UK_Politics:tot_retweets_topic_UK_Politics+
             mean_weekly_sentiment_US_Politics:tot_retweets_topic_US_Politics+
             mean_weekly_sentiment_Violence_Crime:tot_retweets_topic_Violence_Crime+
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week 
          
             
             
             , 
   data= Mod_Dataset)
          
#summary(third_model)

tab_model(sixth_model)

#glimpse(Mod_Dataset)
```

```{r, plot models together, results = 'asis'}

stargazer(first_model, second_model, third_model,
         title = "OLS Regression Results - Satisfaction with Democracy in the UK November 2019 to July 2021",
      #    covariate.labels = c("Treatment", "Time", "Diff-in-Diff"),  # take away other covariates
                               digits = 2, type = "html", header = FALSE, 
         omit.stat = c("f", "ser"), dep.var.labels  = "Satisfaction with Democracy (Binary, 1 = Satisfied)",
         align = TRUE , add.lines = list( c("Region FE", "Yes", "Yes", "Yes"), c("Income FE", "Yes", "Yes", "Yes")), #,
                    notes = "Reference level for Last Vote and Brexit Vote are those who did not vote in each occasion. Only the statistically significant topic-related coefficients are shown here for ease of readibility.",
             #       omit = c( "Constant", "profile_GOR",
              #                "profile_gross_household",
              #                "weekavg_Pandemic_Restrictions",
              #                "weekavg_Enterteinment",
              #                "weekavg_Football_and_Other_Sports",
              #                "weekavg_Home_Stuff",
              #                "weekavg_Life_under_Lockdown",
              #       "weekly_mean_sentiment_R_Pandemic_Restrictions",
              #       "weekly_mean_sentiment_R_Enterteinment",
              #       "weekly_mean_sentiment_R_Everyday_News",
              #       "weekly_mean_sentiment_R_Everyday_Tragedies",
              #       "weekly_mean_sentiment_R_Society",
              #       "weekly_mean_sentiment_R_Royal_family",
        # "weekavg_Royal_family:weekly_mean_sentiment_R_Royal_family	"),
      column.labels   = c("Topic", "Topic+Sentiment", "Interaction"))  #, "week"
                        
                        #  omit = c("Constant", "country"), 
      #   column.sep.width = "7pt", notes = "xx") )
      


```

```{r, plot regression model}

library(jtools)

export_summs(first_model, second_model, scale = TRUE)


```

# Logit Regressions

```{r, logit model 1, eval = FALSE}



first_model_logit<- glm(DEM_SAT ~ weekavg_Climate_Change+
                          weekavg_Covid +
                          weekavg_Crime+
                          weekavg_Daily_News+
                          weekavg_Enterteinment+
                          weekavg_Football+
                          weekavg_Hong_Kong+
                          weekavg_Lockdown+
                          weekavg_Lockdown_Travel+
                          weekavg_Police_Brutality+
                          weekavg_Puppy_News+
                          weekavg_Royal_Family+
                          weekavg_Uk_Politics+
                          weekavg_US_Politics+
                          weekavg_Weather + 
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week, 
   data= Mod_Dataset, family = "binomial")
summary(first_model_logit)

```

```{r, run logit model 2 with weekly sentiment, results = 'asis', eval = FALSE}

## CHANGE MEAN WEEKLY SENTIMENT!!! AND ALSO IN MODEL 3 THE INTERACTION


second_model_logit<- glm(DEM_SAT ~  weekavg_Climate_Change+
                          weekavg_Covid +
                          weekavg_Crime+
                          weekavg_Daily_News+
                          weekavg_Enterteinment+
                          weekavg_Football+
                          weekavg_Hong_Kong+
                          weekavg_Lockdown+
                          weekavg_Lockdown_Travel+
                          weekavg_Police_Brutality+
                          weekavg_Puppy_News+
                          weekavg_Royal_Family+
                          weekavg_Uk_Politics+
                          weekavg_US_Politics+
                          weekavg_Weather +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
              weekavg_Climate_Change+
                          weekly_mean_sentiment_R_Covid +
                          weekly_mean_sentiment_R_Crime+
                          weekly_mean_sentiment_R_Daily_News+
                          weekly_mean_sentiment_R_Enterteinment+
                          weekly_mean_sentiment_R_Football+
                          weekly_mean_sentiment_R_Hong_Kong+
                          weekly_mean_sentiment_R_Lockdown+
                          weekly_mean_sentiment_R_Lockdown_Travel+
                          weekly_mean_sentiment_R_Police_Brutality+
                          weekly_mean_sentiment_R_Puppy_News+
                          weekly_mean_sentiment_R_Royal_Family+
                          weekly_mean_sentiment_R_Uk_Politics+
                          weekly_mean_sentiment_R_US_Politics+
                          weekly_mean_sentiment_R_Weather 
                          
         , 
   data= Mod_Dataset, family = "binomial")
          
#glimpse(Mod_Dataset)

#summary(first_model)
#summary(second_model_logit)

#stargazer(first_model, second_model, type = 'html')


```

```{r, run logit model 3 with interaction topic and sentiment, results = 'asis', eval = FALSE}



third_model_logit<- glm(DEM_SAT ~ weekavg_Pandemic_Restrictions+
                 weekavg_Enterteinment+
                   weekavg_Everyday_News+
                   weekavg_Everyday_Tragedies+
                   weekavg_Family_News+
                   weekavg_Football_and_Other_Sports+
                   weekavg_Home_Stuff+
                   weekavg_Society+
                   weekavg_Life_under_Lockdown+
                   weekavg_Royal_family+
                   weekavg_Pandemic+
                   weekavg_UK_Politics+
                   weekavg_US_Politics+
                 + weekavg_Violence_Crime +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
             weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekly_mean_sentiment_R_Enterteinment+
                   weekly_mean_sentiment_R_Everyday_News+
                   weekly_mean_sentiment_R_Everyday_Tragedies+
                   weekly_mean_sentiment_R_Family_News+
                   weekly_mean_sentiment_R_Football_and_Other_Sports+
                   weekly_mean_sentiment_R_Home_Stuff+
                   weekly_mean_sentiment_R_Society+
                   weekly_mean_sentiment_R_Life_under_Lockdown+
                   weekly_mean_sentiment_R_Royal_family+
                   weekly_mean_sentiment_R_Pandemic+
                   weekly_mean_sentiment_R_UK_Politics+
                   weekly_mean_sentiment_R_US_Politics+
                  weekly_mean_sentiment_R_Violence_Crime +
             weekavg_Pandemic_Restrictions*weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekavg_Family_News*weekly_mean_sentiment_R_Family_News+
             weekavg_Royal_family*weekly_mean_sentiment_R_Royal_family+
             weekavg_Pandemic*weekly_mean_sentiment_R_Pandemic+
             weekavg_UK_Politics*weekly_mean_sentiment_R_UK_Politics+
             weekavg_US_Politics*weekly_mean_sentiment_R_US_Politics+
             weekavg_Violence_Crime*weekly_mean_sentiment_R_Violence_Crime
             
           , 
   data= Mod_Dataset, family = "binomial")
          
#summary(third_model)

#tab_model(third_model)
```

```{r, plot logit models together, results = 'asis', eval = FALSE}

stargazer(first_model_logit, second_model_logit,  title = "Logit Regression Results - Satisfaction with Democracy in the UK November 2019 to December 2021",
      #    covariate.labels = c("Treatment", "Time", "Diff-in-Diff"),  # take away other covariates
                               digits = 2, type = "latex", header = FALSE, 
         omit.stat = c("f", "ser"), dep.var.labels  = "Satisfaction with Democracy (Binary, 1 = Satisfied)",
         align = TRUE , add.lines = list( c("Region FE", "Yes", "Yes"), c("Income FE", "Yes", "Yes")), #,
                    notes = "Reference level for Last Vote and Brexit Vote are those who did not vote in each occasion.",
                    omit = c( "Constant", "profile_GOR",
                              "profile_gross_household"),
      column.labels   = c("Topic", "Topic+Sentiment"),
      column.sep.width = "-3pt")
          #, "week"
                        
                        #  omit = c("Constant", "country"), 
      #   column.sep.width = "7pt", notes = "xx") )
      


```

```{r, plot only one logit model}
stargazer(first_model_logit,  title = "Logit Regression Results - Satisfaction with Democracy in the UK November 2019 to December 2021",
      #    covariate.labels = c("Treatment", "Time", "Diff-in-Diff"),  # take away other covariates
                               digits = 2, type = "latex", header = FALSE, 
         omit.stat = c("f", "ser"), dep.var.labels  = "Satisfaction with Democracy (Binary, 1 = Satisfied)",
         align = TRUE , add.lines = list( c("Region FE", "Yes"), c("Income FE",  "Yes")), #,
                    notes = "Reference level for Last Vote and Brexit Vote are those who did not vote in each occasion.",
                    omit = c( "Constant", "profile_GOR",
                              "profile_gross_household"),
      column.labels   = c("Topic"),
      column.sep.width = "-3pt")
          #, "week"


```

```{r, another way plotting logit model, eval =FALSE}
library(jtools)

setwd("C:/Users/omarh//OneDrive - London School of Economics/Satisfaction_Democracy_Project/")


export_summs(first_model_logit, second_model_logit, scale = TRUE, to.file = "PDF", file.name = "Logit_Models.pdf")

```

# Probit Regressions

```{r, probit model 1, eval = FALSE}



first_model_probit<- glm(DEM_SAT ~ weekavg_Pandemic_Restrictions+
                 weekavg_Enterteinment+
                   weekavg_Everyday_News+
                   weekavg_Everyday_Tragedies+
                   weekavg_Family_News+
                   weekavg_Football_and_Other_Sports+
                   weekavg_Home_Stuff+
                   weekavg_Society+
                   weekavg_Life_under_Lockdown+
                   weekavg_Royal_family+
                   weekavg_Pandemic+
                   weekavg_UK_Politics+
                   weekavg_US_Politics+
                 + weekavg_Violence_Crime +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week, 
   data= Mod_Dataset, family = binomial(link="probit"))


```

```{r, run probit model 2 with weekly sentiment, results = 'asis', eval = FALSE}

## CHANGE MEAN WEEKLY SENTIMENT!!! AND ALSO IN MODEL 3 THE INTERACTION


second_model_probit<- glm(DEM_SAT ~ weekavg_Pandemic_Restrictions+
                 weekavg_Enterteinment+
                   weekavg_Everyday_News+
                   weekavg_Everyday_Tragedies+
                   weekavg_Family_News+
                   weekavg_Football_and_Other_Sports+
                   weekavg_Home_Stuff+
                   weekavg_Society+
                   weekavg_Life_under_Lockdown+
                   weekavg_Royal_family+
                   weekavg_Pandemic+
                   weekavg_UK_Politics+
                   weekavg_US_Politics+
                 + weekavg_Violence_Crime +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
             weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekly_mean_sentiment_R_Enterteinment+
                   weekly_mean_sentiment_R_Everyday_News+
                   weekly_mean_sentiment_R_Everyday_Tragedies+
                   weekly_mean_sentiment_R_Family_News+
                   weekly_mean_sentiment_R_Football_and_Other_Sports+
                   weekly_mean_sentiment_R_Home_Stuff+
                   weekly_mean_sentiment_R_Society+
                   weekly_mean_sentiment_R_Life_under_Lockdown+
                   weekly_mean_sentiment_R_Royal_family+
                   weekly_mean_sentiment_R_Pandemic+
                   weekly_mean_sentiment_R_UK_Politics+
                   weekly_mean_sentiment_R_US_Politics+
                 + weekly_mean_sentiment_R_Violence_Crime , 
   data= Mod_Dataset, family = binomial(link="probit"))
          
#glimpse(Mod_Dataset)

#summary(first_model)
#summary(second_model_logit)

#stargazer(first_model, second_model, type = 'html')


```

```{r, run probit model 3 with interaction topic and sentiment, results = 'asis', eval = FALSE}



third_model_probit<- glm(DEM_SAT ~ weekavg_Pandemic_Restrictions+
                 weekavg_Enterteinment+
                   weekavg_Everyday_News+
                   weekavg_Everyday_Tragedies+
                   weekavg_Family_News+
                   weekavg_Football_and_Other_Sports+
                   weekavg_Home_Stuff+
                   weekavg_Society+
                   weekavg_Life_under_Lockdown+
                   weekavg_Royal_family+
                   weekavg_Pandemic+
                   weekavg_UK_Politics+
                   weekavg_US_Politics+
                 + weekavg_Violence_Crime +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
             weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekly_mean_sentiment_R_Enterteinment+
                   weekly_mean_sentiment_R_Everyday_News+
                   weekly_mean_sentiment_R_Everyday_Tragedies+
                   weekly_mean_sentiment_R_Family_News+
                   weekly_mean_sentiment_R_Football_and_Other_Sports+
                   weekly_mean_sentiment_R_Home_Stuff+
                   weekly_mean_sentiment_R_Society+
                   weekly_mean_sentiment_R_Life_under_Lockdown+
                   weekly_mean_sentiment_R_Royal_family+
                   weekly_mean_sentiment_R_Pandemic+
                   weekly_mean_sentiment_R_UK_Politics+
                   weekly_mean_sentiment_R_US_Politics+
                  weekly_mean_sentiment_R_Violence_Crime +
             weekavg_Pandemic_Restrictions*weekly_mean_sentiment_R_Pandemic_Restrictions+
             weekavg_Family_News*weekly_mean_sentiment_R_Family_News+
             weekavg_Royal_family*weekly_mean_sentiment_R_Royal_family+
             weekavg_Pandemic*weekly_mean_sentiment_R_Pandemic+
             weekavg_UK_Politics*weekly_mean_sentiment_R_UK_Politics+
             weekavg_US_Politics*weekly_mean_sentiment_R_US_Politics+
             weekavg_Violence_Crime*weekly_mean_sentiment_R_Violence_Crime
             
             
             
             
             
             
             
             
             , 
   data= Mod_Dataset, family = binomial(link="probit"))
          
#summary(third_model_probit)

#tab_model(third_model)
```

```{r, plot probit models together, results = 'asis', eval = FALSE}

stargazer(first_model_probit, second_model_probit, third_model_probit,
         title = "Probit Regression Results - Satisfaction with Democracy in the UK November 2019 to July 2021",
      #    covariate.labels = c("Treatment", "Time", "Diff-in-Diff"),  # take away other covariates
                               digits = 2, type = "html", header = FALSE, 
         omit.stat = c("f", "ser"), dep.var.labels  = "Satisfaction with Democracy (Binary, 1 = Satisfied)",
         align = TRUE , add.lines = list( c("Region FE", "Yes", "Yes", "Yes"), c("Income FE", "Yes", "Yes", "Yes")), #,
                    notes = "Reference level for Last Vote and Brexit Vote are those who did not vote in each occasion.",
                    omit = c( "Constant", "profile_GOR",
                              "profile_gross_household",
                              "weekavg_Pandemic_Restrictions",
                              "weekavg_Enterteinment",
                              "weekavg_Football_and_Other_Sports",
                              "weekavg_Home_Stuff",
                              "weekavg_Life_under_Lockdown",
                     "weekly_mean_sentiment_R_Pandemic_Restrictions",
                     "weekly_mean_sentiment_R_Enterteinment",
                     "weekly_mean_sentiment_R_Everyday_News",
                     "weekly_mean_sentiment_R_Everyday_Tragedies",
                     "weekly_mean_sentiment_R_Society",
                     "weekly_mean_sentiment_R_Royal_family",
         "weekavg_Royal_family:weekly_mean_sentiment_R_Royal_family	"),
      column.labels   = c("Topic", "Topic+Sentiment", "Interaction")) 
      #, "week"
                        
                        #  omit = c("Constant", "country"), 
      #   column.sep.width = "7pt", notes = "xx") )
      


```

# Multi-level Modelling


```{r, multi level modelling, eval = FALSE}
#install.packages("lme4")

library(lme4)

t1 <- Sys.time() # Start timer

lm44<- lmer(data = Mod_Dataset, DEM_SAT ~ 
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + #week+ 
             (1+newspaper + lastvote | week) ) 

t2 <- Sys.time() # End timer
t2 - t1

summary(lm44)


r<- ranef(lm44)$week

r$week<-row.names(r) 

r$week<- as.numeric(r$week)

r$date<- as.Date("2019-11-22")+ (r$week - 14)*7


ggplot(r, aes(date, newspaperindependent))+
    geom_line()+
    geom_hline(yintercept = 0)+
  geom_vline(xintercept = as.numeric(as.Date("2020-03-21")), linetype = 4, color = "black")+
      geom_vline(xintercept = as.numeric(as.Date("2020-11-01")), linetype = 4, color = "black")+
        geom_vline(xintercept = as.numeric(as.Date("2021-01-01")), linetype = 4, color = "black")

#22nd november 2019. week 1. 
#glimpse(r)
```

```{r, multi level model 2, eval = FALSE}



summary(lm1)



p<- ranef(lm1)$week

p$week<-row.names(p) 

p$week<- as.numeric(p$week)

p$date<- as.Date("2019-11-22")+ (p$week - 14)*7

library(dplyr)
library(ggplot2)
glimpse(p)

ggplot(p, aes(date, newspaperguardian))+
    geom_line()+
    geom_hline(yintercept = 0)+
  geom_vline(xintercept = as.numeric(as.Date("2020-03-21")), linetype = 4, color = "black")+
      geom_vline(xintercept = as.numeric(as.Date("2020-11-01")), linetype = 4, color = "black")+
        geom_vline(xintercept = as.numeric(as.Date("2021-01-01")), linetype = 4, color = "black")


# Salmond scandal. 


```

```{r, save model, eval = FALSE}

# Save an object to a file
saveRDS(lm1, file = "multi_lev_model.rds")

# Restore the object
readRDS(file = "multi_lev_model.rds")


```

# PLOT Regression models

```{r, plot OLS all variables, eval = FALSE}

 dwplot(list(first_model, second_model), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c("weekavg_Everyday_News","weekavg_Everyday_Tragedies","weekavg_Family_News", "weekavg_Society", 
                "weekavg_Royal_family","weekavg_Pandemic", "weekavg_UK_Politics","weekavg_US_Politics", "weekavg_Violence_Crime",
                "lastvoteConservatives", "lastvoteLabour", "lastvoteLiberal Democrats", "lastvoteOther",
                "lastvoteScottish National Party","pastvote_EURefVoted Leave","pastvote_EURefVoted Remain","newspaperdaily_mail",
                "newspaperdaily_mirror","newspaperft","newspaperguardian","newspaperindependent","newspapersun","newspapertelegraph",
                "newspapertimes","age","profile_genderMale","weekly_mean_sentiment_R_Family_News",
                "weekly_mean_sentiment_R_Football_and_Other_Sports","weekly_mean_sentiment_R_Home_Stuff",
                "weekly_mean_sentiment_R_Life_under_Lockdown","weekly_mean_sentiment_R_Pandemic",
                "weekly_mean_sentiment_R_UK_Politics","weekly_mean_sentiment_R_US_Politics","weekly_mean_sentiment_R_Violence_Crime",
                "weekavg_Family_News:weekly_mean_sentiment_R_Family_News","weekavg_Pandemic:weekly_mean_sentiment_R_Pandemic",
                "weekavg_UK_Politics:weekly_mean_sentiment_R_UK_Politics","weekavg_US_Politics:weekly_mean_sentiment_R_US_Politics",
                "weekavg_Violence_Crime:weekly_mean_sentiment_R_Violence_Crime"
                ))

```

```{r, plot OLS some variables non tweets, eval = FALSE}



 dwplot(list(first_model, second_model, third_model), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c(
                "lastvoteConservatives", "lastvoteLabour", "lastvoteLiberal Democrats", "lastvoteOther",
                "lastvoteScottish National Party","pastvote_EURefVoted Leave","pastvote_EURefVoted Remain","newspaperdaily_mail",
                "newspaperdaily_mirror","newspaperft","newspaperguardian","newspaperindependent","newspapersun","newspapertelegraph",
                "newspapertimes"
                ))+ xlim(breaks = c(-0.3,0.3))+
  ggtitle("OLS Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic", "Topic+Sentiment","Interaction"))



```

```{r, plot OLS some variables tweets, eval = FALSE}



 dwplot(list(first_model, second_model, third_model), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c("weekavg_Everyday_News","weekavg_Everyday_Tragedies","weekavg_Family_News", "weekavg_Society", 
                "weekavg_Royal_family","weekavg_Pandemic", "weekavg_UK_Politics","weekavg_US_Politics", "weekavg_Violence_Crime",
                "weekly_mean_sentiment_R_Family_News",
                "weekly_mean_sentiment_R_Football_and_Other_Sports","weekly_mean_sentiment_R_Home_Stuff",
                "weekly_mean_sentiment_R_Life_under_Lockdown","weekly_mean_sentiment_R_Pandemic",
                "weekly_mean_sentiment_R_UK_Politics","weekly_mean_sentiment_R_US_Politics","weekly_mean_sentiment_R_Violence_Crime",
                "weekavg_Family_News:weekly_mean_sentiment_R_Family_News","weekavg_Pandemic:weekly_mean_sentiment_R_Pandemic",
                "weekavg_UK_Politics:weekly_mean_sentiment_R_UK_Politics","weekavg_US_Politics:weekly_mean_sentiment_R_US_Politics",
                "weekavg_Violence_Crime:weekly_mean_sentiment_R_Violence_Crime"
                ))+ xlim(breaks = c(-0.3,0.3))+
  ggtitle("OLS Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic", "Topic+Sentiment","Interaction"))



```



```{r, plot logit some variables non tweets, eval = FALSE}



 LOGIT1<- dwplot(list(first_model_logit, second_model_logit), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c(
                "lastvoteConservatives", "lastvoteLabour", "lastvoteLiberal Democrats", "lastvoteOther",
                "lastvoteScottish National Party","pastvote_EURefVoted Leave","pastvote_EURefVoted Remain","newspaperdaily_mail",
                "newspaperdaily_mirror","newspaperft","newspaperguardian","newspaperindependent","newspapersun","newspapertelegraph",
                "newspapertimes"
                ))+# xlim(breaks = c(-0.3,0.3))+
  ggtitle("Logit Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic", "Topic+Sentiment"))

LOGIT1

```

```{r, plot logit some variables tweets, eval = FALSE}


 LOGIT2<- dwplot(list(first_model_logit, second_model_logit), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c("weekavg_Climate_Change",
                          "weekavg_Covid" ,
                          "weekavg_Crime",
                          "weekavg_Daily_News",
                          "weekavg_Enterteinment",
                          "weekavg_Football",
                          "weekavg_Hong_Kong",
                          "weekavg_Lockdown",
                          "weekavg_Lockdown_Travel",
                          "weekavg_Police_Brutality",
                          "weekavg_Puppy_News",
                          "weekavg_Royal_Family",
                          "weekavg_Uk_Politics",
                          "weekavg_US_Politics",
                          "weekly_mean_sentiment_R_Covid", 
                          "weekly_mean_sentiment_R_Crime",
                          "weekly_mean_sentiment_R_Daily_News",
                          "weekly_mean_sentiment_R_Enterteinment",
                          "weekly_mean_sentiment_R_Football",
                          "weekly_mean_sentiment_R_Hong_Kong",
                          "weekly_mean_sentiment_R_Lockdown",
                          "weekly_mean_sentiment_R_Lockdown_Travel",
                          "weekly_mean_sentiment_R_Police_Brutality",
                          "weekly_mean_sentiment_R_Puppy_News",
                          "weekly_mean_sentiment_R_Royal_Family",
                          "weekly_mean_sentiment_R_Uk_Politics",
                          "weekly_mean_sentiment_R_US_Politics",
                          "weekly_mean_sentiment_R_Weather" ))+ #xlim(breaks = c(-0.3,0.3))+
  ggtitle("Logit Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic", "Topic+Sentiment"))


LOGIT2
```



# New Logit Models (15 February)

```{r, logit model 1, eval = FALSE}

first_model_logit<- glm(DEM_SAT ~ weekavg_Climate_Change+
                          weekavg_Covid +
                          weekavg_Crime+
                          weekavg_Daily_News+
                          weekavg_Enterteinment+
                          weekavg_Football+
                          weekavg_Hong_Kong+
                          weekavg_Lockdown+
                          weekavg_Lockdown_Travel+
                          weekavg_Police_Brutality+
                          weekavg_Puppy_News+
                          weekavg_Royal_Family+
                          weekavg_Uk_Politics+
                          weekavg_US_Politics+
                          weekavg_Weather + 
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week + new_deaths_per_million + industrial_production + Unemployment, 
   data= Mod_Dataset2, family = "binomial")

summary(first_model_logit)

```

```{r, run logit model 2 with weekly sentiment, results = 'asis', eval = FALSE}

second_model_logit<- glm(DEM_SAT ~  weekavg_Climate_Change+
                          weekavg_Covid +
                          weekavg_Crime+
                          weekavg_Daily_News+
                          weekavg_Enterteinment+
                          weekavg_Football+
                          weekavg_Hong_Kong+
                          weekavg_Lockdown+
                          weekavg_Lockdown_Travel+
                          weekavg_Police_Brutality+
                          weekavg_Puppy_News+
                          weekavg_Royal_Family+
                          weekavg_Uk_Politics+
                          weekavg_US_Politics+
                          weekavg_Weather +
                  profile_gross_household + lastvote +
           pastvote_EURef + newspaper + age + profile_gender  + profile_GOR + week +
              weekavg_Climate_Change+
                          weekly_mean_sentiment_R_Covid +
                          weekly_mean_sentiment_R_Crime+
                          weekly_mean_sentiment_R_Daily_News+
                          weekly_mean_sentiment_R_Enterteinment+
                          weekly_mean_sentiment_R_Football+
                          weekly_mean_sentiment_R_Hong_Kong+
                          weekly_mean_sentiment_R_Lockdown+
                          weekly_mean_sentiment_R_Lockdown_Travel+
                          weekly_mean_sentiment_R_Police_Brutality+
                          weekly_mean_sentiment_R_Puppy_News+
                          weekly_mean_sentiment_R_Royal_Family+
                          weekly_mean_sentiment_R_Uk_Politics+
                          weekly_mean_sentiment_R_US_Politics+
                          weekly_mean_sentiment_R_Weather 
         + new_deaths_per_million + industrial_production + Unemployment,
   data= Mod_Dataset2, family = "binomial")
          
#glimpse(Mod_Dataset)

#summary(first_model)
summary(second_model_logit)

#stargazer(first_model, second_model, type = 'html')


```

```{r, plot logit some variables non tweets, eval = FALSE}

 LOGIT1<- dwplot(list(first_model_logit, second_model_logit), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c(
                "lastvoteConservatives", "lastvoteLabour", "lastvoteLiberal Democrats", "lastvoteOther",
                "lastvoteScottish National Party","pastvote_EURefVoted Leave","pastvote_EURefVoted Remain","newspaperdaily_mail",
                "newspaperdaily_mirror","newspaperft","newspaperguardian","newspaperindependent","newspapersun","newspapertelegraph",
                "newspapertimes"
                ))+# xlim(breaks = c(-0.3,0.3))+
  ggtitle("Logit Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic", "Topic+Sentiment"))

LOGIT1

```

```{r, plot logit some variables tweets, eval = FALSE}


 LOGIT2<- dwplot(list(first_model_logit, second_model_logit), vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2)) +
  ylim(breaks=c("weekavg_Climate_Change",
                          "weekavg_Covid" ,
                          "weekavg_Crime",
                          "weekavg_Daily_News",
                          "weekavg_Enterteinment",
                          "weekavg_Football",
                          "weekavg_Hong_Kong",
                          "weekavg_Lockdown",
                          "weekavg_Lockdown_Travel",
                          "weekavg_Police_Brutality",
                          "weekavg_Puppy_News",
                          "weekavg_Royal_Family",
                          "weekavg_Uk_Politics",
                          "weekavg_US_Politics",
                          "weekly_mean_sentiment_R_Covid", 
                          "weekly_mean_sentiment_R_Crime",
                          "weekly_mean_sentiment_R_Daily_News",
                          "weekly_mean_sentiment_R_Enterteinment",
                          "weekly_mean_sentiment_R_Football",
                          "weekly_mean_sentiment_R_Hong_Kong",
                          "weekly_mean_sentiment_R_Lockdown",
                          "weekly_mean_sentiment_R_Lockdown_Travel",
                          "weekly_mean_sentiment_R_Police_Brutality",
                          "weekly_mean_sentiment_R_Puppy_News",
                          "weekly_mean_sentiment_R_Royal_Family",
                          "weekly_mean_sentiment_R_Uk_Politics",
                          "weekly_mean_sentiment_R_US_Politics",
                          "weekly_mean_sentiment_R_Weather" ))+ xlim(breaks = c(-0.2,0.2))+
  ggtitle("Logit Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic+Sentiment","Topic"))

LOGIT2
````

```{r, plot Logit 1, relabelled variables}

#relabelling
# transform model objects into data frames
m1_tidy <- tidy(first_model_logit) 
m2_tidy <- tidy(second_model_logit) 
# add model name to tidy data frame
m1_tidy <- m1_tidy %>% 
  mutate(model = "Topic")
m2_tidy <- m2_tidy %>% 
  mutate(model = "Topic and Sentiment")
# "glue" model data frames together
all_models <- bind_rows(m1_tidy, m2_tidy)
# relabel predictors, because we want nicer variable names
all_models <- all_models %>% 
        relabel_predictors(c(
              "lastvoteConservatives" = "Voted Conservative",
              "lastvoteLabour" = "Voted Labour",
              "lastvoteLiberal Democrats" = "Voted LibDem",
              "lastvoteOther"= "Voted Other",
              "lastvoteScottish National Party" = "Voted SNP",
              "pastvote_EURefVoted Leave" = "Voted Leave",
              "pastvote_EURefVoted Remain" = "Voted Remain",
              "newspaperdaily_mail" = "Daily Mail",
              "newspaperdaily_mirror" = "The Mirror",
              "newspaperft" = "Financial Times",
              "newspaperguardian" = "The Guardian",
              "newspaperindependent" = "The Independent",
              "newspapersun" = "The Sun",
              "newspapertelegraph"= "The Telegraph",
              "newspapertimes" = "The Times",
                   "weekavg_Climate_Change" = "Salience Climate Change",
                          "weekavg_Covid" = "Salience Covid",
                          "weekavg_Crime" = "Salience Crime",
                          "weekavg_Daily_News" = "Salience Daily News",
                          "weekavg_Enterteinment" = "Salience Entertainment",
                          "weekavg_Football" = "Salience Football",
                          "weekavg_Hong_Kong" = "Salience Hong Kong",
                          "weekavg_Lockdown" = "Salience Lockdown",
                          "weekavg_Lockdown_Travel" = "Salience Lockdown Travel",
                          "weekavg_Police_Brutality" = "Salience Police Brutality",
                          "weekavg_Puppy_News" = "Salience Puppy News",
                          "weekavg_Royal_Family" = "Salience Royal Family",
                          "weekavg_Uk_Politics" = "Salience UK Politics",
                          "weekavg_US_Politics" = "Salience US Politics",
                           "weekavg_Weather" = "Salience Weather",
                          "weekly_mean_sentiment_R_Covid" = "Sentiment Climate Change", 
                          "weekly_mean_sentiment_R_Crime" = "Sentiment Covid",
                          "weekly_mean_sentiment_R_Daily_News" = "Sentiment Daily News",
                          "weekly_mean_sentiment_R_Enterteinment" = "Sentiment Entertainment",
                          "weekly_mean_sentiment_R_Football" = "Sentiment Football",
                          "weekly_mean_sentiment_R_Hong_Kong" = "Sentiment Hong Kong",
                          "weekly_mean_sentiment_R_Lockdown" = "Sentiment Lockdown",
                          "weekly_mean_sentiment_R_Lockdown_Travel" = "Sentiment Lockdown Travel",
                          "weekly_mean_sentiment_R_Police_Brutality" = "Sentiment Police Brutality",
                          "weekly_mean_sentiment_R_Puppy_News" = "Sentiment Puppy News",
                          "weekly_mean_sentiment_R_Royal_Family" = "Sentiment Royal Family",
                          "weekly_mean_sentiment_R_Uk_Politics" = "Sentiment UK Politics",
                          "weekly_mean_sentiment_R_US_Politics" = "Sentiment US Politics",
                          "weekly_mean_sentiment_R_Weather" = "Sentiment Weather"
))

Logit1 <-dwplot(all_models, vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c(
                "Voted Conservative", "Voted Labour", "Voted LibDem", "Voted Other",
                "Voted SNP","Voted Leave","Voted Remain","Daily Mail",
                "The Mirror","Financial Times","The Guardian","The Independent","The Sun","The Telegraph",
                "The Times")
                )+ #xlim(breaks = c(-1,1))+
  ggtitle("Logit Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic+Sentiment", "Topic")) 

setwd("~/Documents/GitHub/Satisfaction_Democracy/data-viz")
ggsave("Logit1.pdf")
Logit1
````

```{r, plot Logit 2, relabelled variables}

Logit2<- dwplot(all_models, vline = geom_vline(
           xintercept = 0, color = "red", linetype = 2))+
  ylim(breaks=c(
                "Salience Climate Change", "Salience Covid", "Salience Crime", "Salience Daily News", "Salience Entertainment", "Salience Football", "Salience Hong Kong", "Salience Lockdown", "Salience Lockdown Travel",  "Salience Police Brutality", "Salience Puppy News", "Salience Royal Family", "Salience UK Politics", "Salience US Politics", "Salience Weather","Sentiment Climate Change",  "Sentiment Covid","Sentiment Daily News", "Sentiment Entertainment","Sentiment Football", "Sentiment Hong Kong", "Sentiment Lockdown", "Sentiment Lockdown Travel",  "Sentiment Police Brutality",  "Sentiment Puppy News", "Sentiment Royal Family", "Sentiment UK Politics", "Sentiment US Politics", "Sentiment Weather")
                )+ xlim(breaks = c(-.22,.22))+
  ggtitle("Logit Models Plot - Selected Variables.\nDV: Satisfaction with Democracy")+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))+
  scale_colour_hue(name = "Models", labels = c("Topic+Sentiment", "Topic")) 

setwd("~/Documents/GitHub/Satisfaction_Democracy/data-viz")
ggsave("Logit2.pdf")
Logit2
````
